package io.geekidea.boot.util.StringUtils;

import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

@Component
public class TimeUtil {

    public static String convertToTimestamp(String dateStr, String pattern) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            // 设置为北京时间时区
            sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
            Date date = sdf.parse(dateStr);
            return String.valueOf(date.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
}
